<?php
	class User{
		var $name;
		var $email;
		var $role;
		var $password;
		var $checklists;

		public function User($email = NULL){
			if(!empty($email)){

				require_once('functions.php');
				$con = getdb();	
				$sql = pg_query($con, "SELECT * FROM usuarios WHERE email = '".$email."'");
				if(pg_num_rows($sql) < 1){
					pg_close($con);
					return false;
				}
				else{
					$this->email = $email;
					$usuario = pg_fetch_row($sql);
					$this->name = $usuario[1];
					$this->role = $usuario[4];
					$this->id = $usuario[0];
					$sql_checklist = pg_query($con, "SELECT * FROM checklists LEFT JOIN usuarios ON checklists.user_id = ".$this->id."");
					$this->checklists = pg_fetch_object($sql_checklist);

					pg_close($con);
					return true;
				}

			}

		}
		public function getName(){
			return $this->name;
		}
		public function getEmail(){
			return $this->email;
		}
		public function getRole(){
			return $this->role;
		}

		public function __destruct(){}


	}
?>